package com.study_online.controller;


import com.study_online.domain.QuestionSubject;
import com.study_online.domain.ResultInfo;
import com.study_online.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;


    //通过面试题类型查找面试题目
    @RequestMapping("/findSubjectByTid")
    public ResultInfo findSubjectByTid(@RequestParam("tid") int tid,
                                       @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {

        ResultInfo info = questionService.findSubjectByTid(tid, pageNum, pageSize);
        return info;
    }

    //模糊查询面试题（题目）
    @RequestMapping("/findSubjectName")
    public ResultInfo finSubjectName(@RequestParam("sname") String questionSName,
                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {

        ResultInfo info = questionService.findSubjectName(questionSName, pageNum, pageSize);
        return info;
    }

    //添加收藏
    @RequestMapping("/addFavorite")
    public ResultInfo addFavorite(@RequestParam("sid") int questionSid,
                                  @RequestParam("uid") int uid) {

        ResultInfo info = questionService.addFavorite(questionSid, uid);
        return info;
    }

    //通过收藏编号删除收藏的面试题目
    @RequestMapping("/delFavorite")
    public ResultInfo delFavoriteByFid(@RequestParam("fid") int questionFid) {
        ResultInfo info = questionService.delFavoriteByFid(questionFid);
        return info;
    }

    //通过用户ID查询用户收藏的面试题目
    @RequestMapping("/findFavoriteByUid")
    public ResultInfo findFavoriteByUid(@RequestParam("uid") int uid,
                                        @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {

        ResultInfo info = questionService.findFavoriteByUid(uid, pageNum, pageSize);
        return info;
    }

    //通过用户ID和题目ID查询用户收藏的面试题目
    @RequestMapping("/findFavoriteByUidAndSid")
    public ResultInfo findFavoriteByUidAndSid(@RequestParam("uid") int uid,
                                              @RequestParam("sid") int questionSid
    ) {

        ResultInfo info = questionService.findFavoriteByUidAndSid(uid, questionSid);
        return info;
    }

    //用户查看自己的错题库
    @RequestMapping("/findWrongByUid")
    public ResultInfo findWrongByUid(@RequestParam("uid") int uid,
                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {
        ResultInfo info = questionService.findWrongByUid(uid, pageNum, pageSize);
        return info;
    }

    //通过错题编号删除错题
    @RequestMapping("/delWrong")
    public ResultInfo delWrongByWid(@RequestParam("wid") int questionWid) {
        ResultInfo info = questionService.delWrongByWid(questionWid);
        return info;
    }

    @RequestMapping("/getQuestions")
    public ResultInfo getQuestions(int sid) {
        return questionService.getQuestions(sid);
    }

}
